import json

# 准备高维数据
lst = [
    {'name':'lily','age':18,'score':86},
    {'name':'lulu','age':24,'score':56},
    {'name':'papi','age':19,'score':66},
]

# ensure_ascii正常显示中文，indent增加缩进
# 编码，列表转成字符串
s = json.dumps(lst,ensure_ascii=False,indent=4)
print(type(s),s)

# 解码
lst2 = json.loads(s)
print(type(lst2),lst2)

# 编码到文件中
with open('student.txt','w') as file:
    json.dump(lst,file,ensure_ascii=False,indent=4)

# 解码到程序
with open('student.txt','r') as file:
    lst3 = json.load(file)
    print(type(lst3),lst3)